package com.zhoutao123.hephaestus.object.transport;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.zhoutao123.hephaestus.repository.entity.BlogComment;
import eu.bitwalker.useragentutils.Browser;
import eu.bitwalker.useragentutils.OperatingSystem;
import eu.bitwalker.useragentutils.UserAgent;
import lombok.Data;

import java.util.UUID;

@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class BlogCommentTO {

    private String blogId;

    private String nickname;

    private String email;

    private String url;

    private String content;

    private String remark;

    private String pid = "0";

    public BlogComment toEntity(UserAgent userAgent) {
        // 获取浏览器信息
        Browser browser = userAgent.getBrowser();
        OperatingSystem operatingSystem = userAgent.getOperatingSystem();

        BlogComment blogComment = new BlogComment();
        blogComment.setId(UUID.randomUUID().toString());
        blogComment.setBlogId(blogId);
        blogComment.setNickname(nickname);
        blogComment.setEmail(email);
        blogComment.setContent(content);
        blogComment.setRemark(remark);
        blogComment.setPid(pid);
        blogComment.setBrowser(browser.getName());
        blogComment.setBrowserShortName(browser.getName());
        blogComment.setOs(operatingSystem.toString());
        return blogComment;
    }
}
